//
//  TwoViewController.m
//  5-31学习
//
//  Created by 钟纪旺 on 16/6/2.
//  Copyright © 2016年 zjw. All rights reserved.
//

#import "TwoViewController.h"

@interface TwoViewController ()

@end

@implementation TwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //开关按钮
    UISwitch *a = [[UISwitch alloc] initWithFrame:CGRectMake(360,8, 66, 66)];
//    d.thumbTintColor =[UIColor blueColor];
    [a addTarget:self action:@selector(omg4:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:a];
    UILabel *l =[[UILabel alloc] initWithFrame:CGRectMake(120,0,800,44)];
    l.text = @"这是一个移动数据开关➡️➡️➡️";
    l.tag =100;
    [self.view addSubview:l];
    UISwitch *b =[[UISwitch alloc] initWithFrame:CGRectMake(360, 50, 44, 44)];
    [self.view addSubview:b];
   [b addTarget:self action:@selector(omg:) forControlEvents:UIControlEventValueChanged];
    UILabel *s =[[UILabel alloc] initWithFrame:CGRectMake(150,44, 800, 44)];
    s.text = @"这是一个变色按钮➡️➡️➡️";
   // s.textColor =[UIColor whiteColor];
    s.tag =200;
    [self.view addSubview:s];
    //UISlider 类似可拉动的
    UISlider *f =[[UISlider alloc] initWithFrame:CGRectMake(16, 200, 100, 44)];
    f.maximumValue =10;
    f.minimumValue =1;
    f.minimumTrackTintColor = [UIColor blueColor];
   f.maximumTrackTintColor = [UIColor redColor];
    [f addTarget:self action:@selector(omg2:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:f];
    
    
    
}

- (void)omg2:(UISlider *)sld {
    
    
    
    if (sld.value <= 2) {
        self.view.backgroundColor =[UIColor redColor];
    }else if (sld.value <=3) {
        self.view.backgroundColor =[UIColor yellowColor];
    }
    else if (sld.value <=5) {
        self.view.backgroundColor =[UIColor blueColor];
    }else if (sld.value <=8){
        self.view.backgroundColor =[UIColor cyanColor];
    }else {
    
        self.view.backgroundColor =[UIColor orangeColor];
    
    }
    

}
// 控制开关修改背景颜色
- (void)omg4:(UISwitch *)swi2 {
    UILabel *l =(UILabel *)[self.view viewWithTag:100];
    if (swi2.isOn) {
        l.text =@"移动数据以打开";
//        l.textColor = [UIColor blackColor];
//        self.view.backgroundColor =[UIColor whiteColor];
        
    }else{
        l.text =@"移动数据以关闭";
//        l.textColor = [UIColor whiteColor];
//        self.view.backgroundColor =[UIColor blackColor];
        
    }
}
- (void)omg:(UISwitch *)swi {

    UILabel *s = (UILabel *)[self.view viewWithTag:200];

    if (swi.isOn) {
        s.text =@"变色";
        s.textColor = [UIColor blackColor];
        self.view.backgroundColor =[UIColor redColor];
        
    }else{
        s.text =@"变色";
        s.textColor = [UIColor whiteColor];
        self.view.backgroundColor =[UIColor cyanColor];
        
    }




}
//- (IBAction)updateValue :(UISlider *)sender{
//    if (sender.value == 1) {
//         self.view.backgroundColor =[UIColor redColor];
//    }else {
//        self.view.backgroundColor =[UIColor cyanColor];
//
//    }
//    float f = sender.value;
//
//
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
